﻿package lobby
{
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import lobby.exchangeddata.HashTable;
	import lobby.exchangeddata.LobbyUserInfo;
	import lobby.events.LobbyEvent;
	
	import lobby.common.Utility;
	
	/**
	 * ...
	 * @author ... Doan Nguyen Thuy Nha Truc (Bamboo)
	 */
	public class AccountInfoPanel extends MovieClip
	{
		public var txtAccInfoTf:TextField;
		public var txtAccNameTf:TextField;
		public var txtAccNameValueTf:TextField;
		
		public var txtAccBalanceTf:TextField;
		public var txtAccBalanceValueTf:TextField;
		public var txtCurrentPassTf:TextField;
		public var txtNewPassTf:TextField;
		public var txtConfirmNewPassTf:TextField;
		
		public var txtCommRateTf:TextField;
		public var txtCommRateValueTf:TextField;
		public var txtUpperLimitTf:TextField;
		public var txtUpperLimitValueTf:TextField;
		public var txtLowerLimitTf:TextField;
		public var txtLowerLimitValueTf:TextField;
		public var txtOldPassTi:TextField;
		public var txtNewPassTi:TextField;
		public var txtConfirmPassTi:TextField;
		public var txtOkTf:TextField;
		public var txtCancelTf:TextField;
		public var btnAcceptNewPass:SimpleButton;
		public var btnCancelChangePass:SimpleButton;
		public var accountInfo:LobbyUserInfo;
		
		public function AccountInfoPanel()
		{
			accountInfo = new LobbyUserInfo();
			hide();
			this.btnCancelChangePass.useHandCursor = true;
			this.btnAcceptNewPass.useHandCursor = true;
			this.txtOkTf.mouseEnabled = false;
			this.txtCancelTf.mouseEnabled = false;
			this.btnCancelChangePass.addEventListener(MouseEvent.CLICK, clickCancelChangePassHdl);
			this.btnAcceptNewPass.addEventListener(MouseEvent.CLICK, clickAcceptNewPassHdl);
			this.btnAcceptNewPass.tabEnabled = false;
			this.btnCancelChangePass.tabEnabled = false;
		}
		
		private function clickAcceptNewPassHdl(e:MouseEvent):void
		{
			var event:LobbyEvent = new LobbyEvent(LobbyEvent.SHOW_MS, true);
			var valueMs:String;
			trace("keke");
			if (this.txtOldPassTi.text == "")
			{
				valueMs = GlobalVariables.langInfo.hashTable.lookupString("RequireOldPassword");
				event.ms = valueMs;
				dispatchEvent(event);
			}
			else
			{
				if (this.txtNewPassTi.text == this.txtConfirmPassTi.text)
				{
					if (this.txtNewPassTi.text == "")
					{
						valueMs = GlobalVariables.langInfo.hashTable.lookupString("RequireNewPassword");
						event.ms = valueMs;
						dispatchEvent(event);
					}
					else
					{
						event = new LobbyEvent(LobbyEvent.CHANGE_PASS, true);
						accountInfo.oldPass = this.txtOldPassTi.text;
						accountInfo.newPass = this.txtNewPassTi.text;
						dispatchEvent(event);
						hide();
					}
					
				}
				else
				{
					valueMs = GlobalVariables.langInfo.hashTable.lookupString("ReEnterPasswordNotMatch");
					event.ms = valueMs;
					dispatchEvent(event);
				}
			}
			
		}
		
		private function clickCancelChangePassHdl(e:MouseEvent):void
		{
			hide();
			this.txtOldPassTi.text = "";
			this.txtNewPassTi.text = "";
			this.txtConfirmPassTi.text = "";
		}
		
		public function show():void
		{
			this.visible = true;
		
		}
		
		public function hide():void
		{
			this.visible = false;
		}
		
		public function initText(hashTableInfo:HashTable):void
		{
			this.txtAccInfoTf.text = hashTableInfo.lookupString("accountMSG");
			this.txtAccNameTf.text = hashTableInfo.lookupString("anameMSG");
			this.txtAccBalanceTf.text = hashTableInfo.lookupString("balanceMSG");
			this.txtUpperLimitTf.text = hashTableInfo.lookupString("ulimitMSG");
			this.txtLowerLimitTf.text = hashTableInfo.lookupString("llimitMSG");
			this.txtCommRateTf.text = hashTableInfo.lookupString("cRateMsg");
			this.txtCurrentPassTf.text = hashTableInfo.lookupString("cpassMSG");
			this.txtNewPassTf.text = hashTableInfo.lookupString("npassMSG");
			this.txtConfirmNewPassTf.text = hashTableInfo.lookupString("ccpassMSG");
			this.txtOkTf.text = hashTableInfo.lookupString("btnOK");
			this.txtCancelTf.text = hashTableInfo.lookupString("btnCancel");
			this.txtOldPassTi.text = "";
			this.txtNewPassTi.text = "";
			this.txtConfirmPassTi.text = "";
		
		}
		
		public function updateValueAccountInfo(info:Object):void
		{
			
			var accountInfo:LobbyUserInfo = LobbyUserInfo(info);
			this.accountInfo = LobbyUserInfo(info);
			
			/*accountInfo.username = "david";
			   accountInfo.balance = "500";
			   accountInfo.commissionRate = 0;
			   accountInfo.maxBet = 500;
			   accountInfo.minBet = 50;
			 */
			trace("accountInfo.balance:" + accountInfo.balance + ":accountInfo.commissionRate :" + accountInfo.commissionRate + ":accountInfo.maxBet:" + accountInfo.maxBet + ":accountInfo.minBet:" + accountInfo.minBet);
			
			trace("k : " + accountInfo.username);
			this.txtAccNameValueTf.text = accountInfo.username;
			this.txtAccBalanceValueTf.text = Utility.currency(Number(accountInfo.balance), 2, "");
			this.txtCommRateValueTf.text = Utility.currency(accountInfo.commissionRate, 2, "");
			this.txtUpperLimitValueTf.text = accountInfo.maxBet + "";
			this.txtLowerLimitValueTf.text = accountInfo.minBet + "";
		}
	}

}